package Data;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class Connector {
	public ChannelSftp sftpconnect() {
		Session session = null;
		Channel channel = null;
		ChannelSftp channelSftp = null;

		String username = "root";
		String host = "192.168.238.128";
		Integer port = 22;
		String password = "hadoop";

		JSch jsch = new JSch();

		try {
			session = jsch.getSession(username, host, port);
			session.setPassword(password);

			java.util.Properties config = new java.util.Properties();
			config.put("StrictHostKeyChecking", "no");
			session.setConfig(config);

			session.connect();
			channel = session.openChannel("sftp");

			channel.connect();
		} catch (JSchException e) {
			e.printStackTrace();
		}
		channelSftp = (ChannelSftp)channel;
		return channelSftp;
	}
	
	public ChannelExec sshconnect() {
		Session session = null;
		Channel channel = null;
		ChannelExec channelExec = null;

		String username = "hadoop";
		String host = "192.168.238.128";
		Integer port = 22;
		String password = "hadoop";

		JSch jsch = new JSch();

		try {
			session = jsch.getSession(username, host, port);
			session.setPassword(password);

			java.util.Properties config = new java.util.Properties();
			config.put("StrictHostKeyChecking", "no");
			session.setConfig(config);

			session.connect();
			channel = session.openChannel("exec");

			
		} catch (JSchException e) {
			e.printStackTrace();
		}
		channelExec = (ChannelExec)channel;
		return channelExec;
	}
}